<div class="profiles form profilesmapedit">
<?php echo $form->create('Profile', array('type' => 'file', 'action'=>'editmap'));?>
	<fieldset>
 		<legend><?php __('Edit Profile');?></legend>
		<?php echo $this->renderElement('mapjs'); ?>
		<div id="map"></div>
		
		<script type="text/javascript" charset="utf-8">
			//<![CDATA[
			
			google.load("maps", "2.x");
			
			jQuery(document).ready(function() {
				if (GBrowserIsCompatible()) {
				var map = new GMap2(jQuery("#map").get(0));
				map.addControl(new GLargeMapControl());
				<?php
				if(empty($this->data['Profile']['zoom'])) {
					$zoom = Configure::read('Map.zoom');
				} else {
					$zoom = $this->data['Profile']['zoom'];
				}
				$lat = $this->data['Profile']['latitude'];
				$lon = $this->data['Profile']['longitude'];
				echo "var zoom = $zoom;
					var lat = $lat;
					var lon = $lon;
					"
				?>
				var point = new GLatLng(lat,lon);
				var marker = new GMarker(point, {draggable: true});
				map.addOverlay(marker);
				map.setCenter(point, zoom);
				
				GEvent.addListener(map, "zoomend", function() {
					jQuery("#ProfileZoom").val(map.getZoom());
				});
				
				GEvent.addListener(marker, "dragend", function() {
					map.panTo(marker.getLatLng());
					jQuery("#ProfileLatitude").val(marker.getLatLng().lat());
					jQuery("#ProfileLongitude").val(marker.getLatLng().lng());
				});
				
				}
			});
			//]]>
		</script>	
	<?php
		echo $form->input('id');
		echo $form->input('location');
		echo $form->hidden('latitude');
		echo $form->hidden('longitude');
		echo $form->hidden('zoom');
	?>	
	</fieldset>
	<div class="secondary">
		<fieldset>
			<legend><?php echo Configure::read('Profile.map_title')?></legend>
			<p><?php echo Configure::read('Profile.map_body')?></p>
		</fieldset>	
	</div>
	<div class="block">
		<div class="element">
			<?php echo $form->submit(__('Save profile', true));?>
		</div>
		<div class="element">
			<?php echo $html->link(__('Cancel and go back', true), array('action'=>'home'),array('class'=>'button-cancel') );?>
		</div>
	</div>
	<?php echo $form->end();?>
</div>

